<template>
  <div class="container">
    <div class="welcome">
      <div class="pink1">
        <pinkOcean />
      </div>
      <div class="pinkbox">
        <!-- 注册 -->
        <div class="signup nodisplay">
          <h1>注册</h1>
          <el-form
            ref="registerForm"
            :model="registerForm"
            :rules="registerRules"
            auto-complete="on"
            @submit.prevent="signIn"
            autocomplete="off"
          >
            <el-form-item prop="username">
              <span class="svg-container">
                <svg-icon icon-class="user" />
              </span>
              <el-input
                ref="username"
                v-model.trim="registerForm.username"
                placeholder="请输入您的账号"
                name="username"
                type="text"
                tabindex="1"
                auto-complete="on"
              />
            </el-form-item>
            <el-form-item prop="email">
              <span class="svg-container">
                <svg-icon icon-class="user" />
              </span>
              <el-input
                ref="email"
                v-model="registerForm.email"
                placeholder="Useremail"
                name="email"
                type="text"
                tabindex="1"
                auto-complete="on"
              />
            </el-form-item>
            <el-form-item prop="password">
              <span class="svg-container">
                <svg-icon icon-class="password" />
              </span>
              <el-input
                :key="passwordType"
                ref="password"
                v-model="registerForm.password"
                :type="passwordType"
                placeholder="Password"
                name="password"
                tabindex="2"
                auto-complete="on"
                @keyup.enter.native="handleLogin"
              />
              <span class="show-pwd" @click="showPwd">
                <svg-icon
                  :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'"
                />
              </span>
            </el-form-item>

            <el-form-item prop="repassword">
              <span class="svg-container">
                <svg-icon icon-class="password" />
              </span>
              <el-input
                :key="passwordType"
                ref="repassword"
                v-model="registerrules1.repassword"
                :type="passwordType"
                placeholder="请再次输入密码"
                name="repassword"
                tabindex="2"
                auto-complete="on"
                @keyup.enter="signIn"
              />
              <span class="show-pwd" @click="showPwd">
                <svg-icon
                  :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'"
                />
              </span>
            </el-form-item>

            <el-button
              :loading="loading"
              type="primary"
              style="width: 65%; margin-bottom: 30px"
              @click="signIn"
              >注册</el-button
            >
          </el-form>
        </div>

        <!-- 登录 -->
        <div class="signin">
          <h1>大笨钟邮局</h1>
          <el-form
            ref="loginForm"
            :model="loginForm"
            :rules="loginRules"
            class="login-form more-padding"
            auto-complete="on"
            label-position="left"
            autocomplete="off"
          >
            <el-form-item prop="identifier">
              <span class="svg-container">
                <svg-icon icon-class="user" />
              </span>
              <el-input
                ref="identifier"
                v-model="loginForm.identifier"
                placeholder="请输入账号"
                name="identifier"
                type="text"
                tabindex="1"
                auto-complete="on"
              />
            </el-form-item>
            <el-form-item prop="password">
              <span class="svg-container">
                <svg-icon icon-class="password" />
              </span>
              <el-input
                :key="passwordType"
                ref="password"
                v-model="loginForm.password"
                :type="passwordType"
                placeholder="请输入密码"
                name="password"
                tabindex="2"
                auto-complete="on"
                @keyup.enter.native="handleLogin"
              />
              <span class="show-pwd" @click="showPwd">
                <svg-icon
                  :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'"
                />
              </span>
            </el-form-item>
            <el-button
              class="btn1"
              :loading="loading"
              type="primary"
              style="width: 65%; margin-bottom: 30px"
              @click.native.prevent="handleLogin"
              >登录</el-button
            >
          </el-form>
        </div>
      </div>

      <div class="leftbox">
        <button class="button" id="signin">登陆</button>
      </div>

      <div class="rightbox">
        <button class="button" id="signup">注册</button>
      </div>
    </div>
  </div>
</template>

<script>
import * as jquery from "jquery";
import "echarts-liquidfill";
import { register } from "@/api/user";
import login from '@/components/login/login.vue';
export default {
     components: { login },
  name: "Login",
  data() {
    const validatePassword = (rule, value, callback) => {
      if (value.length < 6) {
        callback(new Error("The password can not be less than 6 digits"));
      } else {
        callback();
      }
    };
    const validatePass2 = (rule, value, callback) => {
      console.log(191, value);
      if (value === "") {
        callback(new Error("请再次输入密码"));
      } else if (value !== this.registerrules1.password) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };
    return {
      endId: "",
      loginForm: {
        identifier: "admin",
        password: "adminadmin",
      },
      registerForm: {
        username: "admin123",
        email: "example@qq.com",
        password: "adminadmin",
      },
      findForm: {
        username: "",
        email: "",
        password: "",
      },
      registerrules1: {
        repassword: "adminadmin",
      },
      loginRules: {
        identifier: [
          { required: true, message: "用户名不能为空！", trigger: "blur" },
        ],
        password: [
          {
            required: true,
            trigger: "blur",
            message: "密码不能为空！",
            validator: validatePassword,
          },
        ],
      },
      registerRules: {
        username: [
          { required: true, message: "用户名不能为空！", trigger: "blur" },
        ],
        password: [
          {
            required: true,
            trigger: "blur",
            message: "密码不能为空！",
            validator: validatePassword,
          },
        ],
        email: [{ required: true, trigger: "blur", message: "邮箱不能为空！" }],
        repassword: [
          {
            required: true,
            trigger: ["blur", "change"],
            validator: validatePass2,
          },
        ],
      },
      loading: false,
      passwordType: "password",
      redirect: undefined,
    };
  },
  watch: {
    endId(newvalue, oldvalue) {
      clearInterval(oldvalue);
      return newvalue;
    },
  },
  methods: {
    // 账号密码显示隐藏
    showPwd() {
      if (this.passwordType === "password") {
        this.passwordType = "";
      } else {
        this.passwordType = "password";
      }
      this.$nextTick(() => {
        this.$refs.password.focus();
      });
    },
    // 登录
    async handleLogin() {
      this.$refs.loginForm.validate();
      await this.$store.dispatch("user/getlogin", this.loginForm);
      this.$router.push("/");
    },
    //注册
    async signIn() {
      const formData = this.$refs.registerForm;
      console.log(278, formData.model); //.data.props.model
      this.registerForm = formData.model;
      console.log(280, this.registerForm);
      const res = await register(this.registerForm);
      this.loginForm.identifier = this.registerForm.username;
      this.loginForm.password = this.registerForm.password;
      console.log(this.loginForm, 294);
      console.log(266, res);
      jquery(".pinkbox").css("transform", "translateX(0%)"); //关闭注册表单，打开登陆表单
      jquery(".signup").addClass("nodisplay");
      jquery(".signin").removeClass("nodisplay");
    },
  },
  mounted() {
    jquery("#signup").click(function () {
      jquery(".pinkbox").css("transform", "translateX(80%)");
      jquery(".signin").addClass("nodisplay");
      jquery(".signup").removeClass("nodisplay");
    });

    jquery("#signin").click(function () {
      jquery(".pinkbox").css("transform", "translateX(0%)");
      jquery(".signup").addClass("nodisplay");
      jquery(".signin").removeClass("nodisplay");
    });
  },
};
</script>

<style scoped>
.pink1 {
  /* z-index: 99; */
  overflow: hidden;
  width: 100%;
  height: 100%;
  border-radius: 5px;
}
/* 容器的样式 */
.container {
  margin: auto;
  width: 650px;
  height: 550px;
  position: relative;
}

.welcome {
  /* overflow: hidden; */
  background: #f6f6f6;
  width: 650px;
  height: 415px;
  position: absolute;
  top: 40%;
  border-radius: 5px;
  box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.1);
}

.pinkbox {
  position: absolute;
  top: -10%;
  left: 4%;
  background: rgb(142, 212, 240);
  width: 330px;
  height: 500px;
  border-radius: 5px;
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
  transition: all 0.5s ease-in-out;
  z-index: 2;
}
.btn1{
    margin-top: 15px;
}
.nodisplay {
  display: none;
  transition: all 0.5s ease;
}

.leftbox,
.rightbox {
  position: absolute;
  width: 50%;
  top: -0px;
  transition: 1s all ease;
  z-index: 1;
}

.leftbox {
  left: -2%;
}

.rightbox {
  right: -2%;
}

/* 字体和按钮的样式 */
h1 {
  font-family: "Open Sans", sans-serif;
  text-align: center;
  margin-top: 50px;
  text-transform: uppercase;
  color: #f6f6f6;
  font-size: 2em;
  letter-spacing: 8px;
}

.title {
  font-family: "Lora", serif;
  color: #8e9aaf;
  font-size: 1.8em;
  line-height: 1.1em;
  letter-spacing: 3px;
  text-align: center;
  font-weight: 300;
  margin-top: 20%;
}

.desc {
  margin-top: -8px;
}

.account {
  margin-top: 45%;
  font-size: 10px;
}

p {
  font-family: "Open Sans", sans-serif;
  font-size: 0.7em;
  letter-spacing: 2px;
  color: #8e9aaf;
  text-align: center;
}

span {
  color: #eac7cc;
}

.flower {
  position: absolute;
  width: 150px;
  height: 150px;
  top: 45%;
  left: 27%;
  opacity: 0.8;
}

.smaller {
  width: 130px;
  height: 130px;
  top: 48%;
  left: 30%;
  opacity: 0.9;
}

button {
  padding: 12px;
  font-family: "Open Sans", sans-serif;
  text-transform: uppercase;
  letter-spacing: 3px;
  font-size: 11px;
  border-radius: 10px;
  margin: auto;
  outline: none;
  display: block;
}


.button {
  margin-top: 40%;
  background: #f6f6f600;
  color: #ce7d88;
  font-size: 100px;
  opacity: 0
}

/* 表单样式 */
form {
  display: flex;
  align-items: center;
  flex-direction: column;
  padding-top: 7px;
}

.more-padding {
  padding-top: 35px;
}

.more-padding input {
  padding: 12px;
}

.more-padding .sumbit {
  margin-top: 45px;
}

.sumbit {
  margin-top: 25px;
  padding: 12px;
  border-color: #ce7d88;
}


input {
  background: #eac7cc;
  width: 65%;
  color: #ce7d88;
  border: none;
  border-bottom: 1px solid rgba(246, 246, 246, 0.5);
  padding: 9px;
  font-weight: 100;
}

input::placeholder {
  color: #f6f6f6;
  letter-spacing: 2px;
  font-size: 1em;
  font-weight: 100;
}

input:focus {
  color: #ce7d88;
  outline: none;
  border-bottom: 1.2px solid rgba(206, 125, 136, 0.7);
  font-size: 1em;
  transition: 0.8s all ease;
}

input:focus::placeholder {
  opacity: 0;
}

label {
  font-family: "Open Sans", sans-serif;
  color: #ce7d88;
  font-size: 0.8em;
  letter-spacing: 1px;
}

.checkbox {
  display: inline;
  white-space: nowrap;
  position: relative;
  left: -52px;
  top: 25px;
}

input[type="checkbox"] {
  width: 15px;
  background: #ce7d88;
}

.checkbox input[type="checkbox"]:checked + label {
  color: #ce7d88;
  transition: 0.5s all ease;
}
</style>
<style lang="scss" scoped>
$bg: #2d3a4b;
$dark_gray: #889aa4;
$light_gray: #eee;

.login-container {
  min-height: 100%;
  width: 100%;
  background-color: $bg;
  overflow: hidden;

  .login-form {
    position: relative;
    height: 100%;
    width: 520px;
    max-width: 100%;
    margin: 0 auto;
    overflow: hidden;
  }
  .div3 {
    border-radius: 15px;
    position: relative;
    height: 100%;
    width: 520px;
    max-width: 100%;
    transform: translate(0%, -100%);
    margin: 0 auto;
  }
  .pink {
    width: 100%;
    height: 100%;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
  }
  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;

    .title {
      font-size: 26px;
      color: $light_gray;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
}
.div1 {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}
.div2 {
  width: 100%;
  height: 100%;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
</style>
<style lang="scss">
$bg: #283443;
$light_gray: #fff;
$cursor: #fff;

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: $cursor;
  }
}

/* reset element-ui css */
.login-container {
  .el-input {
    display: inline-block;
    height: 47px;
    width: 85%;

    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: $light_gray;
      height: 47px;
      caret-color: $cursor;

      &:-webkit-autofill {
        box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-text-fill-color: $cursor !important;
      }
    }
  }

  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    color: #454545;
  }
}
</style>